package com.ruoyi.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.service.FlowInstanceServiceImpl;
import com.ruoyi.vo.FlowTaskVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * <p>工作流流程实例管理<p>
 *
 * @author XuanXuan
 *
 */
@Slf4j
@RestController
@RequestMapping("/flowable/instance")
public class FlowInstanceController {

    @Autowired
    private FlowInstanceServiceImpl flowInstanceService;

    
    @PostMapping("/startBy/{procDefId}")
    public AjaxResult startById(@PathVariable(value = "procDefId") String procDefId,
                                @RequestBody Map<String, Object> variables) {
        return flowInstanceService.startProcessInstanceById(procDefId, variables);

    }


    
    @PostMapping(value = "/updateState")
    public AjaxResult updateState(@RequestParam Integer state,
                                  @RequestParam String instanceId) {
        flowInstanceService.updateState(state,instanceId);
        return AjaxResult.success();
    }

    
    @PostMapping(value = "/stopProcessInstance")
    public AjaxResult stopProcessInstance(@RequestBody FlowTaskVO flowTaskVo) {
        flowInstanceService.stopProcessInstance(flowTaskVo);
        return AjaxResult.success();
    }

    
    @DeleteMapping(value = "/delete")
    public AjaxResult delete( @RequestParam String instanceId,
                             @RequestParam(required = false) String deleteReason) {
        flowInstanceService.delete(instanceId,deleteReason);
        return AjaxResult.success();
    }
}